#include <QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <climits>
#include <algorithm>
using namespace std;

void sortirovka1(int* mass,int size, int sposob)
{
    if (sposob==1)
    {
        for (int i=0; i<size; i++)
            for (int j=i+1; j<size; j++)
                if (mass[i]<mass[j])
                {
                        int d=mass[i];
                        mass[i]=mass[j];
                        mass[j]=d;
                }
    }
    else if (sposob==2)
    {
        for (int i=0; i<size; i++)
            for (int j=i+1; j<size; j++)
                if (mass[i]>mass[j])
                {
                        int d=mass[i];
                        mass[i]=mass[j];
                        mass[j]=d;
                }
    }


}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);



    int size1, size2;
    cout<<"Vvedite razmernosti\n";
    cin>>size1>>size2;

    int** mass2=new int*[size1];
    for (int i = 0; i < size1; i++)
            mass2[i] = new int [size2];

    for (int i=0; i<size1; i++)
        for (int j=0; j<size2; j++)
            mass2[i][j]=rand();
    cout<<"Vash massiv\n";
    for (int i=0; i<size1; i++)
    {
        for (int j=0; j<size2; j++)
            cout<<mass2[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    cout<<"Viberite sposob sortirovki: 1-po ubyvaniyu, 2-po vozrastaniyu: ";
    int sposob;
    cin>>sposob;
    int odnomer[size1*size2];
    int count=0;
    for (int i=0; i<size1; i++)
        for (int j=0; j<size2; j++)
        {
            odnomer[count]=mass2[i][j];
            count++;
        }
    sortirovka1(odnomer, size1*size2, sposob);

    count=0;
    for (int i=0; i<size1; i++)
        for (int j=0; j<size2; j++)
        {
            mass2[i][j]=odnomer[count];
            count++;
        }
    cout<<"Vash new massiv\n";
    for (int i=0; i<size1; i++)
    {
        for (int j=0; j<size2; j++)
            cout<<mass2[i][j]<<" ";
        cout<<endl;
    }


    return a.exec();
}
